package com.le.tester.javaThink.fifth.chapter24_ConcurrentProgramming;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * createTime：2021/8/23 17:37
 * description：GuardedIDField
 */
public class GuardedIDField implements HasID {

    private static AtomicInteger counter = new AtomicInteger();

    //保证线程的安全性
    private int id = counter.getAndIncrement();

    @Override
    public int getID() {
        return id;
    }

    public static void main(String[] args) {
        IDChecker.test(GuardedIDField::new);
    }
}
